#include <acme/windows.h>

// The active ingredient of 'sudo' is the Linker directive that adds a UAX Execution level of 'requireAdministrator' to the manifest file.
// This causes Windows 6 and up to elevate the sudo execution
// sudo then passes its command line to CreateProcess, causing the child process to inherit the current (elevated) execution level.

using namespace acme::windows;

LPTSTR GetFirstArgPtr(LPTSTR str)
{
  while(*str && *str != ' ')
  {
    if(*str == '\"')
    {
      str++;
      while(*str && *str != '\"')
      {
        str++;
      }
      if(*str =='"')
        str++;
    }
    else
      str++;
  }
  if(*str == ' ')
    str++;
  return *str?str:NULL;
}


int main()
{
  LPTSTR cmdLine = GetCommandLine();
  LPTSTR subCmdLine = GetFirstArgPtr(cmdLine);

  return Process::System(subCmdLine);
}

